<%@page import="com.wowangz.cms.common.utils.MessageObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<script type="text/javascript">
	function view(id){
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/dailyoperation/store/storeView.web?id="+id + "&approval=2"
		});
	}
	function approvrInfo(flag,msg){
		var ids = getIds(2);
		if (ids != '' && ids != undefined) {
			if(confirm(msg)){
				// 显示进度条
				showSending();
				$.ajax({
					type: 'POST',
				    url: '${systemctx}/dailyoperation/store/batchStartOrStop.web?flag='+flag+"&ids="+ids,
				    data: $("#form1").serialize(),
				    dataType: 'json',
				    success: function(data) {
				    	//关闭执行...
						closeSending();
				    	if(data.code == 200){
				    		alert(data.message);
				    		query_datagrid();
				    	}else {
				    		alert(data.message);
				    		return;
				    	}
				    }
				});
			}
		}
	}
	
	function query_datagrid(flag){
		var state = $("#state").val();
		var name = $("#name").val();
		//加载分页控件 datagrid
		$('#datagrid').issdatagrid({
			formid : 'form1',
			title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.list.title")%>',
			width : 'auto',
			nowrap : true,
			autoRowHeight : false,
			singleSelect : false,
			striped : true,
			url : '${systemctx}/dailyoperation/store/getManageJson.json?',
			sortName : 'modifytime',
			sortOrder : 'desc',
			remoteSort : true,
			idField : 'id',
			pagination : true,
			rownumbers : true,
			showFooter : true,
			queryParams:$('#form1').serializeObject(),
			frozenColumns :[[
 				{field:'ck', checkbox:true},
 				{field : 'id',title : '<%=MessageResourcesUtils.getMessage(request, "common.button.operation")%>',width : 50,align : 'center',formatter : function(val, row,index) {
	      			var str = '';
	    			str  +="<a href=\"javascript:void(0);\" class=\"easyui-linkbutton\" onclick=\"editInfo('" + val + "')\">修改</a> ";
	    			return str;
 				}},
  				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.number")%>',field : 'number',sortable : true,align : 'left',formatter: function(value,row,index){
  					return "<a href=\"javascript:void(0);\" onclick=\"view('"+row.id+"')\">"+value+"</a>";
  				}
  				},  
  				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name")%>',field : 'name',sortable : true,align : 'left',width:200,formatter: function(value,row,index){
  					return "<span title='"+value+"'>"+value+"</span>";					
  				}}, 
  				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.corporate")%>',field : 'corporate',sortable : true,align : 'left',width:120}
              
              ]],
			columns : [[ 
              	{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.quality")%>',field : 'quality',sortable : true,align : 'left',width:120}, 
	            {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.population")%>',field : 'population',sortable : true,align : 'left',width:80}, 
	            {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.industry")%>',field : 'industry',sortable : true,align : 'left',width:120}, 
	            {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.businesslicensecode")%>',field : 'businesslicensecode',sortable : true,align : 'left',width:160}, 
              	{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.organizationcode")%>',field : 'organizationcode',sortable : true,align : 'left',width:160}, 
              	{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.certificatecode")%>',field : 'certificatecode',sortable : true,align : 'left',width:160},
	            {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.realname")%>',field : 'realname',sortable : true,align : 'left',width:150}, 
	            {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.bussisstatus")%>',field : 'businessstatus',sortable : true,align : 'center',width:70}
            ]],
			onLoadSuccess : function(data) {

			}
		});
	}
	function editInfo(ids){
		if (ids != '' && ids != undefined) {
			$(this).isswindow({
				noheader : true,
				url :"${systemctx}/dailyoperation/store/findOne?id="+ids
			});
		}
	}
	$(document).ready(function() {
		$("#state").selectutil({
			optModel : <%=SysConstant.CommonApproveStatus.getMode1JSONString(true, false)%>
		});
		query_datagrid();
		$('#butQuery').click(function() {
			$("#flag").val(1);
			$('#datagrid').datagrid('load',$('#form1').serializeObject());
		});
	});
	
	function getIds(flag) {
		var ids = "";
		var rows = $('#datagrid').datagrid('getChecked');
		if (rows.length == 0) {
			alert("<%=MessageResourcesUtils.getMessage(request, "dailyoperation.selects.warning")%>");
			return;
		} else {
			if (flag == 1) {
				if (rows.length > 1) {
					alert("<%=MessageResourcesUtils.getMessage(request, "dailyoperation.selects.edit.warning")%>");
					return;
				} else {
					ids = rows[0].id;
					return ids;
				}
			} else {
				for (var i = 0; i < rows.length; i++) {
					ids += rows[i].id + ",";
				}
				if (ids != '') {
					ids = ids.substring(0,ids.length - 1);
				}
				return ids;
			}
		}
	}
	
	
	function sendemail() {
		var ids = "";
		var rows = $('#datagrid').datagrid('getChecked');
		if (rows.length == 0) {
			alert("<%=MessageResourcesUtils.getMessage(request, "dailyoperation.selects.warning")%>");
			return;
		} else {
			// 显示进度条
			showSending();
			var length = rows.length;
			for(var i = 0; i < length;i ++) {
				var row = rows[i];
				ids += row.id + ",";
			}
			$.getJSON('${systemctx}/dailyoperation/store/resetSendEmail.json?ids=' + ids ,function(data){
				//关闭执行...
				closeSending();
				if(data.resposecode =='<%=MessageObject.ResponseCode.code_200%>') {
					alert(data.message);
				} else {
					alert(data.message);
					return;
				}
			});
		}
	}
</script>

<form name="form1" id="form1">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.manage.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.list") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name") %>
						</label>
						<span>
							<input type="text" name="name" id="name">
							<input type="hidden"  name="flag" id="flag">
						</span>
					</li>
				</ul>
			</div>	
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" value="<%=MessageResourcesUtils.getMessage(request, "common.button.query")%>" />
			<input type="button" class="btn btn-default" onclick="approvrInfo('1','<%=MessageResourcesUtils.getMessage(request, "dailyoperattionstore.common.useage.confirm.info1") %>')" value="启用" />
			<input type="button" class="btn btn-default" onclick="approvrInfo('2','<%=MessageResourcesUtils.getMessage(request, "dailyoperattionstore.common.useage.confirm.info2") %>')" value="停用" />
			<input type="button" class="btn btn-default" onclick="sendemail()" value="发送邮件" />
		</div>
		<table width="100%">
			<tbody>
				<tr>
					<td>
						<table id="datagrid"></table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</form>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>